#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>

void sighandler (int signal)
{
    pid_t pid = waitpid(-1,NULL,0);
    printf("回收子进程为: pid=%d\n",pid);
}

int main(int argc, char const *argv[])
{
    //signal(SIGCHLD,sighandler);
    signal(SIGRTMIN,sighandler);

    for (int i = 0; i < 10; i++)
    {
        if (fork() == 0)
        {
            printf("chaild pid =%d\n",getpid());
            sleep(10);
            kill(getppid(),SIGRTMIN);
            exit(0);
        }
        
    }
    printf("main process is running\n");
    while (1)
    { 
        sleep(1);
    }

    return 0;
}
